#include <iostream>
using namespace std;

int main()
{
    int a = 10;
    
    //1、引用必须初始化 -- 指针可以不被初始化
    // error: int& b;
    int& b = a;
    
    //2、引用在初始化后，不可以改变
    int c = 20;
    b = c; // 赋值操作，不是更改引用。 -- b是a的别名

    cout << "a = " << a << endl;
    cout << "b = " << b << endl;
    cout << "c = " << c << endl;

    cout << "=================" << endl;

    //3、指针与引用的联合使用
    int a2 = 3, b2 = 5;
    int& m = a2; //ok 
    // int& m; //error
    // int& m = b2; //error
    int& k = m;
    int n = m;
    int* p = &m;
    int*& ref = p; // ref是p指针的别名
    m = m + 5;
    
    cout << "a2 = " << a2 << endl;
    cout << "b2 = " << b2 << endl;
    cout << "m = " << m << endl;
    cout << "k = " << k << endl;
    cout << "n = " << n << endl;
    cout << "*p = " << *p << endl;
    cout << "*ref = " << *ref << endl;
    
    return 0;
}